package top.riske.gen3d.controller;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;
import top.riske.gen3d.common.DTO.JwtDto;
import top.riske.gen3d.entity.Hunyuan3DJob;
import top.riske.gen3d.http.response.Result;
import top.riske.gen3d.service.Hunyuan3DJobService;

import java.util.List;

@RestController
@RequestMapping("/api")
public class JobController {

    @Resource
    private Hunyuan3DJobService hunyuan3DJobService;

    /**
     * 获取用户的任务列表
     * @param jwtDto 用户信息
     * @return 任务列表
     */
    @GetMapping("/protected/user/job/list")
    public Result<List<Hunyuan3DJob>> getJobList(JwtDto jwtDto, HttpServletRequest request){
        return Result.success(hunyuan3DJobService.getJobsByAccountId(jwtDto.getUid(), request));
    }

    /**
     * 删除任务
     * @param id 任务主键ID
     * @param jwtDto 用户信息
     * @return
     */
    @PostMapping("/protected/user/job/delete")
    public Result<Boolean> deleteJob(@RequestParam Long id, JwtDto jwtDto){
        return Result.success(hunyuan3DJobService.deleteJob(id, jwtDto.getUid()));
    }

    /**
     * 搜索任务，全文索引，模糊搜索
     * @param target 搜索目标
     * @return
     */
    @GetMapping("/protected/user/search/text")
    public Result<List<Hunyuan3DJob>> searchJobByFullText(String target){
        return Result.success(hunyuan3DJobService.selectJobWithFileByFullText(target));
    }

    /**
     * 搜索任务，AI搜索
     * @param target
     * @return
     */
    @GetMapping("/public/user/search/ai")
    public Result<List<Hunyuan3DJob>> searchJobByAi(String target, HttpServletRequest request){
        return Result.success(hunyuan3DJobService.searchLikeByAi(target, request));
    }

    /**
     * 添加任务到我的任务
     * @param id 任务主键ID
     * @return
     */
    @PostMapping("/protected/user/job/addToMine")
    public Result<Hunyuan3DJob> addJobToMine(@RequestParam Long id, JwtDto jwtDto){
        return Result.success(hunyuan3DJobService.addJobToMine(id,jwtDto.getUid()));
    }


}
